package ciyuan.Gui.Bar;

import ciyuan.Player.Skill.SkillUtils;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

/**
 * @author 150149
 */
@Mod.EventBusSubscriber(value = Dist.CLIENT)
public class SkillBar extends AbstractGui{

    @SubscribeEvent
    public static void onOverlayRender(RenderGameOverlayEvent event) {
        if (event.getType() != RenderGameOverlayEvent.ElementType.ALL) {
            return;
        }
        if (Minecraft.getInstance().player == null ) {
            return;
        }

        if (SkillUtils.getSkillPercentage(Minecraft.getInstance().player)==0) {
            return;
        }

        int i = Minecraft.getInstance().getWindow().getGuiScaledWidth() / 2 - 91;
        SkillBar skillBAr = new SkillBar();
        skillBAr.renderJumpMeter(event.getMatrixStack(),i);
    }

    public void renderJumpMeter(MatrixStack p_238446_1_, int p_238446_2_) {
        Minecraft.getInstance().getTextureManager().bind(AbstractGui.GUI_ICONS_LOCATION);
        float f = SkillUtils.getSkillPercentage(Minecraft.getInstance().player);
        int i = 182;
        int j = (int)(f * 183.0F);
        int k = Minecraft.getInstance().getWindow().getGuiScaledHeight() - 32 + 3;
        this.blit(p_238446_1_, p_238446_2_, k, 0, 84, 182, 5);
        if (j > 0) {
            this.blit(p_238446_1_, p_238446_2_, k, 0, 89, j, 5);
        }

    }

}
